package vno.sci.window
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import hr.binaria.asx3m.converters.basic.NullConverter;
	
	import org.aswing.AsWingManager;
	
	import vno.fux.res.pool.BitmapAttacher;
	import vno.sci.event.MonologEvent;

	public class OPopup extends Sprite
	{
		private var frame:OFrame;
		
		/**
		 * 原来的窗口改编的。 
		 * @param text 
		 * @param button1
		 * @param button2
		 * @param frameBG
		 * @param textBG
		 * 
		 */		
		public function OPopup(text:String, button1:String = "OK", button2:String = "Cancel", frameBG:BitmapAttacher = null, textBG:BitmapAttacher = null)
		{
			//AsWingManager.initAsStandard(parent_);
			frame = new OFrame(this,false,frameBG,textBG);
			
			// send input to Controller
			frame.prevBtn.addEventListener(MouseEvent.CLICK,handlePrev);
			frame.nextBtn.addEventListener(MouseEvent.CLICK,handleNext);
			
			frame.prevBtn.setText(button1);
			frame.nextBtn.setText(button2);
			frame.text.setText(text);
			frame.text.setEditable(false);
			
			// add to Parent as a child
			frame.show();
			
		}
		
		protected function handleNext(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			event.stopImmediatePropagation();
			dispatchEvent(new MonologEvent(0,MonologEvent.PREVIOUS,event.bubbles,event.cancelable));
		}
		
		protected function handlePrev(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			event.stopImmediatePropagation();
			dispatchEvent(new MonologEvent(0,MonologEvent.NEXT, event.bubbles, event.cancelable));
		}
		
		public function close():void
		{
			frame.hide();
			frame = null;
			
		}
	}
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.net.URLRequest;

import mx.skins.Border;

import org.aswing.AsWingManager;
import org.aswing.AssetBackground;
import org.aswing.BoxLayout;
import org.aswing.EmptyLayout;
import org.aswing.JButton;
import org.aswing.JFrame;
import org.aswing.JLabel;
import org.aswing.JPanel;
import org.aswing.JPopup;
import org.aswing.JScrollPane;
import org.aswing.JTextArea;
import org.aswing.JWindow;
import org.aswing.event.FrameEvent;
import org.aswing.event.ResizedEvent;

import vno.fux.res.pool.BitmapAttacher;
import vno.sci.event.MonologEvent;
import vno.sci.window.MyButton;



class OFrame extends JPopup
{
	public var buttonHeight:int = 30;
	public var titleHeight:int = 0;
	
//	public var myTitle:JLabel = new JLabel("Title");
	public var text:JTextArea = new JTextArea();
	public var textPane:JScrollPane = new JScrollPane(text);
	
	//	public var prevBtn:JButton = new JButton("Previous");
	
	//ok 4
//	private var skin:Bitmap = new Bitmap(new BitmapData(100,100,false,0x13579b));
//	private var skin2:Bitmap = new Bitmap(new BitmapData(100,100,false,0x79acae));
//	private var skin3:Bitmap = new Bitmap(new BitmapData(100,100,false,0xace000));
//	public var prevBtn:MyButton = new MyButton("PrevBtn", null, "Prev",skin,skin2,skin3);
	
	public var prevBtn:JButton = new JButton("Prev");
	public var nextBtn:JButton = new JButton("Next");
	public var buttonLayout:BoxLayout = new BoxLayout(BoxLayout.X_AXIS,10);
	public var buttonBar:JPanel = new JPanel(buttonLayout);
	
	public var windowWidth:int = 300;
	public var windowHeight:int = 200;

	
//	public var _btn:JButton = new JButton("_");
//	public var obtn:JButton = new JButton("o");
//	public var xbtn:JButton = new JButton("X");
//	public var controlButtonPane:JPanel = new JPanel();
	
	
	
	
	//	public function OFrame(owner:* = null, modal:Boolean = false, frameBackground:BitmapData = null, textBackground:BitmapData = null)
	public function OFrame(owner:* = null, modal:Boolean = false, frameBackground:BitmapAttacher = null, textBackground:BitmapAttacher = null)
	{
		
		super(owner,modal)
		
		this.setLayout(new EmptyLayout());
		
		this.setSizeWH(windowWidth,windowHeight);
		
		// add skin to frame and text.
		if (frameBackground && textBackground)
		{
			var frameDecorator:AssetBackground = new AssetBackground(frameBackground);
			this.setBackgroundDecorator(frameDecorator);
			var textDecorator:AssetBackground = new AssetBackground(textBackground);
			text.setBackgroundDecorator(textDecorator);
		}
		
		//begin layout
		//buttonBar
		buttonBar.appendAll(prevBtn,nextBtn);
		buttonBar.setSizeWH(windowWidth*3/4,buttonHeight);
		buttonBar.setLocationXY((windowWidth-buttonBar.width)/2,windowHeight-buttonHeight);
		
		//textPane
		textPane.setSizeWH(this.width*3/4, this.height-buttonHeight-titleHeight);
		textPane.setLocationXY((windowWidth-textPane.width)/2,titleHeight);
		text.setWordWrap(true);
		text.setText("");
		text.setBorder(null);
		
		//title
//		myTitle.setSizeWH(this.width, titleHeight);
//		myTitle.setLocationXY(0,0);
		
		//end layout
//		this.append(myTitle);
		//newly added 20130511.213817
//		controlButtonPane.append(xbtn);
//		controlButtonPane.setSizeWH(25*controlButtonPane.numChildren,25);
//		controlButtonPane.setLocationXY(this.width-25*controlButtonPane.numChildren,0);
		
//		this.append(controlButtonPane);
		this.append(textPane);
		this.append(buttonBar);
	}
	
//	public function setTitle(string:String):void
//	{
//		myTitle.setText(string);
//	}
}